<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>发送 GET 请求</title>
</head>
<body>
    <button>点击发送 AJAX 请求</button>
    <script>
        //点击按钮 向 http://127.0.0.1/getUser, 控制台输出响应报文结果
        //获取元素
        let btn = document.querySelector('button');;

        //绑定事件
        btn.onclick = function(){
          let x = new XMLHttpRequest();
          x.open('get','http://127.0.0.1/getUser?username=lalala&t='+Date.now());
          x.send();

          x.onreadystatechange = function(){
              if(x.readyState === 4 && x.status === 200){
                 console.log(x.response);
              }
          }
        }
    </script>
</body>
</html>